(function (angular) {
	'use strict';

	angular
		.module('xianwan')
		.factory('Platform', ['$rootScope', 'Constant', function ($rootScope, Constant) {
			let platform = window.platform;


			function getPlatform() {
				return platform;
			}

			function getPlatformSplit() {
				/* let split = '';

				if (platform === 'window') {
					split = '\\';
				}
				if (platform === 'mac') {
					split = '/';
				}

				return split; */

				if (process.platform === 'darwin') {
					return '/';
				}
				return '\\';
			}

			function concatPath(path1, path2) {
				let split = getPlatformSplit();

				return path1 + split + path2;
			}

			function getNameByPath(path) {
				if (!path) return '';
				let name = '';
				let split = getPlatformSplit();

				return path.substring(path.lastIndexOf(split) + 1);
			}

			function getAbsolutePath(path) {
				if (!path) return '';

				let split = getPlatformSplit();

				return path.substring(0, path.lastIndexOf(split)) + split;
			}

			function getRequestParams(path) {
				if (!path) return {};

				let split = getPlatformSplit();
				path = path.split(':\/\/')[1];
				let serverPath = path.substring(0, path.indexOf('\/')).split(':');
				let basePath = path.substr(path.indexOf('\/'));

				return {
					'hostname': serverPath[0],
					'port': serverPath[1] || (Constant.MEDIA_SERVER_URL_IS_HTTPS ? 443 : 80),
					'path': basePath
				}
			}

			return {
				getPlatform: getPlatform,
				concatPath: concatPath,
				getNameByPath: getNameByPath,
				getAbsolutePath: getAbsolutePath,
				getRequestParams: getRequestParams
			};
		}
		]);
})(angular);